﻿Imports DataAccess
Imports Entities
Public Class PedidoBL
    Public Shared Function Save(ByVal zObject As PEDIDOS, ByVal zList As List(Of DETALLEPEDIDO)) As Boolean
        Try
            Dim pedido = PedidoDAL.Create(zObject)
            For Each rec In zList
                rec.PEDIDO = pedido.PEDIDO
                DetallePedidoDAL.Create(rec)
            Next
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function List() As List(Of PEDIDOS)
        Dim lista As New List(Of PEDIDOS)
        lista = PedidoDAL.List
        If lista.Count > 0 Then
            Return lista
        Else
            Return Nothing
        End If
    End Function
    Public Shared Function ListP(zIdProveedor) As List(Of PedidoP)
        Dim lista As New List(Of ITEMES)
        Dim listaP As New List(Of PedidoP)
        lista = ItemBL.ListByProveedorId(zIdProveedor)

        For Each rec In lista
            Dim p As New PedidoP
            Dim g = GarantiaBL.SearchById(rec.GARANTIA)
            With p
                .ItemId = rec.ITEM
                .GarantiaId = rec.GARANTIA
                .Descripcion = rec.DESCRIPCION
                .Kilos = rec.CANTIDADKILOS
                .Stock = rec.STOCK
                .StockGarantia = 0
                .CantidadPedido = 0
            End With
            listaP.Add(p)
        Next
        Return listaP
    End Function

    Public Shared Function SearchById(ByVal zId As Long) As PEDIDOS
        Dim bol As New PEDIDOS
        bol = PedidoDAL.SearchById(zId)
        Return bol
    End Function

    Public Shared Function List4ByProveedorId(ByVal zId As Long) As List(Of PEDIDOS)
        Dim PedidosList = PedidoDAL.List4ByProveedorId(zId)
        Dim ListaFinal As New List(Of PEDIDOS)
        For Each pedido In PedidosList
            If Not FacturaDAl.CheckPedido(pedido.PEDIDO) Then
                ListaFinal.Add(pedido)
            End If
        Next
        Return ListaFinal
    End Function

    Public Shared Function GetDetallePedido(ByVal zId As Long) As List(Of DETALLEPEDIDO)
        Return PedidoDAL.ListDetallePedido(zId)
    End Function


End Class
